# -*- coding: utf-8 -*-
import urllib,urllib2,cookielib
import os,sys,time
import re,json



# 登录界面url
# Request URL:http://f.10086.cn/im5/login/login.action
# Request Method:GET
# Status Code:200 OK
# Request Headersview source
# Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; user=13957861878; pass=33g02g04; JSESSIONID=B347C9AE148CAFFB.2201
# Host:f.10086.cn
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Response Headersview source
# Connection:keep-alive
# Content-Encoding:gzip
# Content-Language:zh-CN
# Content-Type:text/html; charset=UTF-8
# Date:Fri, 20 Jan 2012 02:54:09 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked

# 登录发送url
# Request URL:http://f.10086.cn/im5/login/loginHtml5.action?t=35846377398631847
# Request Method:POST
# Status Code:200 OK
# Request Headersview source
# Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Cache-Control:max-age=0
# Connection:keep-alive
# Content-Length:27
# Content-Type:application/x-www-form-urlencoded
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04
# Host:f.10086.cn
# Origin:http://f.10086.cn
# Referer:http://f.10086.cn/im5/login/login.action
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Query String Parametersview URL encoded
# t:35846377398631847
# Form Dataview URL encoded
# m:13957861878
# pass:33g02g04
# Response Headersview source
# Connection:keep-alive
# Content-Encoding:gzip
# Content-Language:zh-CN
# Content-Type:text/html; charset=UTF-8
# Date:Fri, 20 Jan 2012 02:55:00 GMT
# Server:nginx/0.7.61
# Set-Cookie:cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; path=/; expires=Sat, 19-Jan-2013 02:55:00 GMT; HttpOnly, loginstatusCookie=400; path=/; expires=Sat, 19-Jan-2013 02:55:00 GMT; HttpOnly
# Transfer-Encoding:chunked


# Request URL:http://f.10086.cn/im5/index/html5.action?t=35846427929166847
# Request Method:GET
# Status Code:200 OK
# Request Headersview source
# Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Referer:http://f.10086.cn/im5/login/loginHtml5.action?t=35846377398631847
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Query String Parametersview URL encoded
# t:35846427929166847
# Response Headersview source
# Connection:keep-alive
# Content-Encoding:gzip
# Content-Language:zh-CN
# Content-Type:text/html; charset=UTF-8
# Date:Fri, 20 Jan 2012 02:55:01 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked


# Request URL:http://f.10086.cn/im5/index/queryFriends.action?fromUrl=main&from=1&_=1327028099173
# Request Method:GET
# Status Code:200 OK
# Request Headersview source
# Accept:application/json, text/javascript, */*
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Referer:http://f.10086.cn/im5/index/html5.action?t=35846427929166847
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Query String Parametersview URL encoded
# fromUrl:main
# from:1
# _:1327028099173
# Response Headersview source
# Connection:keep-alive
# Content-Language:zh-CN
# Content-Type:text/json; charset=utf-8
# Date:Fri, 20 Jan 2012 02:55:02 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked

# 好友列表
'''
{
    "total": 11,
    "friendTotal": 8,
    "contacts": [
        {
            "idContact": 300139237,
            "localName": "cc",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 857571023,
            "mobileNo": "13732118890",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:857571023@fetion.com.cn;p=3222",
            "nickname": "",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 288160052,
            "localName": "ice",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 713921405,
            "mobileNo": "13566031076",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:713921405@fetion.com.cn;p=1561",
            "nickname": "ice",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "-164095478"
        },
        {
            "idContact": 495009164,
            "localName": "陈凯",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 540578836,
            "mobileNo": "13806672701",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:540578836@fetion.com.cn;p=3967",
            "nickname": "",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 291376594,
            "localName": "灰兔",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 595173769,
            "mobileNo": "13586827430",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:595173769@fetion.com.cn;p=1769",
            "nickname": "灰兔",
            "impresa": "熊猫人，鸟人，植物人",
            "impresaLength": 18,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 306747281,
            "localName": "徐丰",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 118046558,
            "mobileNo": "13805878985",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:118046558@fetion.com.cn;p=3959",
            "nickname": "",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 705892217,
            "localName": "尤波",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 964208719,
            "mobileNo": "13757492517",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:964208719@fetion.com.cn;p=3475",
            "nickname": "",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 501615213,
            "localName": "徐均",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 0,
            "mobileNo": "13819834204",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 0,
            "services": "",
            "smsOnlineStatus": "0.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "tel:13819834204",
            "nickname": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": ""
        },
        {
            "idContact": 345124391,
            "localName": "游客",
            "relationStatus": 1,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 632548988,
            "mobileNo": "",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "365.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:632548988@fetion.com.cn;p=6245",
            "nickname": "游客",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 299148354,
            "localName": "554468190",
            "relationStatus": 0,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 554468190,
            "mobileNo": "",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 1,
            "services": "99",
            "smsOnlineStatus": "365.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "sip:554468190@fetion.com.cn;p=2958",
            "nickname": "",
            "impresa": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": "0"
        },
        {
            "idContact": 316068362,
            "localName": "手机好友",
            "relationStatus": 0,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 0,
            "mobileNo": "",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 0,
            "services": "",
            "smsOnlineStatus": "365.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "tel:13957863152",
            "nickname": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": ""
        },
        {
            "idContact": 515010163,
            "localName": "手机好友",
            "relationStatus": 0,
            "contactType": 0,
            "isBlocked": 0,
            "permission": "identity=1;",
            "idFetion": 0,
            "mobileNo": "",
            "email": "",
            "carrier": "CMCC",
            "carrierStatus": 0,
            "basicServiceStatus": 0,
            "services": "",
            "smsOnlineStatus": "365.0:0:0",
            "presenceBasic": "0",
            "presenceDesc": "",
            "deviceType": "",
            "uri": "tel:13605888337",
            "nickname": "",
            "impresaLength": 0,
            "newMsgNums": 0,
            "portraitCrc": ""
        }
    ]
}
'''

'''
增加好友（未确认）           回复Y（开通飞信并加好友）                     回复J（不开通飞信但加好友）
{
  "idContact": 300139237,    "idContact": 300139237,                       idContact: 501615213
  "localName": "1373211..",  "localName": "857571023",                     localName: "1381983.."
  "relationStatus": 0,       "relationStatus": 1,                          relationStatus: 1
  "contactType": 0,          "contactType": 0,                             contactType: 0
  "isBlocked": -1,           "isBlocked": 0,                               isBlocked: 0
  "permission": "",          "permission": "",                             permission: ""
  "idFetion": 0,             "idFetion": 857571023,                        idFetion: 0
  "mobileNo": "13732118890", "mobileNo": "13732118890",                    mobileNo: "13819834204"
  "email": "",               "email": "",                                  email: ""
  "carrier": "",             "carrier": "CMCC",                            carrier: "CMCC"
  "carrierStatus": -1,       "carrierStatus": 0,                           carrierStatus: 0
  "basicServiceStatus": 1,   "basicServiceStatus": 1,                      basicServiceStatus: 0
  "services": "",            "services": "99",                             services: ""
  "smsOnlineStatus": "",     "smsOnlineStatus": "0.0:0:0",                 smsOnlineStatus: "0.0:0:0"
  "presenceBasic": "",       "presenceBasic": "0",                         presenceBasic: "0"
  "presenceDesc": "",        "presenceDesc": "",                           presenceDesc: ""
  "deviceType": "",          "deviceType": "",                             deviceType: ""
  "uri": "tel:13732118890",  "uri": "sip:857571023@fetion.com.cn;p=3222",  uri: "tel:13819834204"
  "nickname": "",            "nickname": "",                               nickname: ""
  "impresa": "",             "impresa": "",                                impresa: ""
  "impresaLength": 0,        "impresaLength": 0,                           impresaLength: 0
  "newMsgNums": 0,           "newMsgNums": 0,                              newMsgNums: 0
  "portraitCrc": ""          "portraitCrc": "0"                            portraitCrc: ""
}
'''


# 发送消息界面
# Request URL:http://f.10086.cn/im5/chat/sendNewMsg.action
# Request Method:POST
# Status Code:200 OK
# Request Headersview source
# Accept:*/*
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Content-Length:77
# Content-Type:application/x-www-form-urlencoded
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Origin:http://f.10086.cn
# Referer:http://f.10086.cn/im5/chat/toChatMsg.action?touserid=705892217&html5Url=toChat&t=1327028098697
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Form Dataview URL encoded
# touserid:705892217
# msg:发送消息测试
# Response Headersview source
# Connection:keep-alive
# Content-Language:zh-CN
# Content-Type:text/json; charset=utf-8
# Date:Fri, 20 Jan 2012 02:58:56 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked

# 发送消息
# Request URL:http://f.10086.cn/im5/chat/sendNewMsg.action
# Request Method:POST
# Status Code:200 OK
# Request Headersview source
# Accept:*/*
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Content-Length:191
# Content-Type:application/x-www-form-urlencoded
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Origin:http://f.10086.cn
# Referer:http://f.10086.cn/im5/chat/toChatMsg.action?touserid=291376594&html5Url=toChat&t=1327033572021
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Form Dataview URL encoded
# touserid:291376594
# msg:测试车辆违章自动提醒消息。车牌号：浙B12345
# Response Headersview source
# Connection:keep-alive
# Content-Language:zh-CN
# Content-Type:text/json; charset=utf-8
# Date:Fri, 20 Jan 2012 04:27:57 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked

# {"info":消息发送成功!}

# 退出
# Request URL:http://f.10086.cn/im5/index/logoutsubmit.action
# Request Method:GET
# Status Code:200 OK
# Request Headersview source
# Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Referer:http://f.10086.cn/im5/chat/toChatMsg.action?touserid=705892217&html5Url=toChat&t=1327028098697
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Response Headersview source
# Connection:keep-alive
# Content-Encoding:gzip
# Content-Language:zh-CN
# Content-Type:text/html; charset=UTF-8
# Date:Fri, 20 Jan 2012 04:04:22 GMT
# Server:nginx/0.7.61
# Set-Cookie:cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; path=/; expires=Thu, 01-Dec-1994 16:00:00 GMT; HttpOnly, loginstatusCookie=400; path=/; expires=Thu, 01-Dec-1994 16:00:00 GMT; HttpOnly
# Transfer-Encoding:chunked


# 加好友手机号码
# Request URL:http://f.10086.cn/im5/user/addFriendSubmit.action?number=13805878985&type=0&t=1327036515950
# Request Method:GET
# Status Code:200 OK
# Request Headersview source
# Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Referer:http://f.10086.cn/im5/user/addfriend.action?t=35854840805175847
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Query String Parametersview URL encoded
# number:13805878985
# type:0
# t:1327036515950
# Response Headersview source
# Connection:keep-alive
# Content-Encoding:gzip
# Content-Language:zh-CN
# Content-Type:text/html; charset=UTF-8
# Date:Fri, 20 Jan 2012 05:15:33 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked


# Request URL:http://f.10086.cn/im5/chat/sendNewShortMsg.action
# Request Method:POST
# Status Code:200 OK
# Request Headersview source
# Accept:*/*
# Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
# Accept-Encoding:gzip,deflate,sdch
# Accept-Language:en-US,zh-CN;q=0.8,zh;q=0.6
# Connection:keep-alive
# Content-Length:43
# Content-Type:application/x-www-form-urlencoded
# Cookie:WT_FPC=id=211.140.39.195-500956624.30115731:lv=1327025787090:ss=1327025522065; JSESSIONID=B347C9AE148CAFFB.2201; user=13957861878; pass=33g02g04; cell_cookie=b5c26219730d4b83a3e01161d25686d1|09431270ad042e08ddc33e51de704474; loginstatusCookie=400
# Host:f.10086.cn
# Origin:http://f.10086.cn
# Referer:http://f.10086.cn/im5/chat/toChatMsg.action?touserid=705892217&html5Url=toChat&t=35860666117257847
# User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.18 (KHTML, like Gecko) Chrome/18.0.1010.1 Safari/535.18
# Form Dataview URL encoded
# touserid:705892217
# msg:aaaaaaaaaaaaaaaaaaaa
# Response Headersview source
# Connection:keep-alive
# Content-Language:zh-CN
# Content-Type:text/json; charset=utf-8
# Date:Fri, 20 Jan 2012 06:52:36 GMT
# Server:nginx/0.7.61
# Transfer-Encoding:chunked


def fetion(msg):
    url_login = 'http://f.10086.cn/im5/login/loginHtml5.action'
    # url_html5 = 'http://f.10086.cn/im5/index/html5.action'
    url_queryfriends = 'http://f.10086.cn/im5/index/queryFriends.action'
    # url_addfriend = 'http://f.10086.cn/im5/user/addfriend.action'
    # url_searchfriend = 'http://f.10086.cn/im5/user/searchFriendByPhone.action'
    url_addfriendsubmit = 'http://f.10086.cn/im5/user/addFriendSubmit.action'
    url_sendsmg = 'http://f.10086.cn/im5/chat/sendNewShortMsg.action'
    url_sendmsg = 'http://f.10086.cn/im5/chat/sendNewMsg.action'
    url_logout = 'http://f.10086.cn/im5/index/logoutsubmit.action'
    '''
    buddylist	1   好友列表
    localName	    无用
    nickname	3分100   最多5个中文或5个英文
    number	13705743215
    type	0   0是手机号
    '''
    
    
    user = '13957861878'
    password = '33g02g04'
    t = ''
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)
    print 'Logining...'
    login_req = urllib2.Request(url_login, urllib.urlencode({'pass':password, 'm':user}))
    login_res = urllib2.urlopen(login_req).read()
    # print page.decode('utf-8')
    t = re.compile(r't=(\d+)').findall(login_res)[0]
    print t
    # html5 = urllib2.Request(url_html5, urllib.urlencode({'t':t}))
    # print opener.open(html5).read().decode('utf-8')
    firends_req = urllib2.Request(url_queryfriends)
    firends = urllib2.urlopen(firends_req).read()
    firends = json.loads(firends)
    for x in firends['contacts']:
        # if x['relationStatus']:
        print x['relationStatus'],x['idContact'],x['localName'],x['mobileNo']
    
    # print opener.open(firends).read().decode('utf-8')
    
    # addfriend = urllib2.Request(url_addfriendsubmit, urllib.urlencode({'number':'18668227758','type':'0','t':t}))
    # print opener.open(addfriend).read().decode('utf-8')
    sendmsg = urllib2.Request(url_sendsmg, urllib.urlencode({'touserid':'316152686','msg':'这条消息是程序发的，收到打个电话来'}))
    # '{"info":消息发送成功!}'
    print opener.open(sendmsg).read().decode('utf-8')

    logout_req = urllib2.Request(url_logout, urllib.urlencode({'t':t}))
    logout = urllib2.urlopen(logout_req).read()


    '''
    url = re.compile(r'<card id="start".*?ontimer="(.*?);').findall(page)[0] 
    if url == '/im/login/login.action':
        print "error"
        return
    # sendmsg = urllib2.Request(url_mymsg, urllib.urlencode({'msg':msg}))
    sendmsg = urllib2.Request(url_invit, urllib.urlencode({'buddylist':'1','localName':'这是测试帐号','nickname':'违章3分','number':'13705743215','type':'0'}))
    finish = urllib2.urlopen(sendmsg)

    # if finish.geturl == 'http://f.10086.cn/im/user/sendMsgToMyself.action' :
    if finish.geturl == url_invit :
        print 'Send Failed!'
    else:
        print 'Send Successfully'
    logout = urllib2.Request(url_logout + t)
    response = urllib2.urlopen(logout) 
    print 'Logout Successfully!'
    print response.read().decode('utf-8').encode('gbk')
    '''
fetion('aaa')